package com.itany.ems.service.impl;


import com.itany.ems.Util.ParameterUtil;
import com.itany.ems.dao.EmpDao;
import com.itany.ems.entity.Emp;
import com.itany.ems.exception.DataAccessException;
import com.itany.ems.exception.RequestParameterErrorException;
import com.itany.ems.exception.ServiceException;
import com.itany.ems.impl.EmpDaoImpl;
import com.itany.ems.service.EmpService;

import java.util.List;



public class EmpServiceImpl implements EmpService {

    @Override
    public void addEmp(String name, String salary, String gender, String edu, String[] hobbies) {

    }

    @Override
    public void Register(String name, String salary, String gender, String edu, String[] hobbies) throws RequestParameterErrorException, ServiceException {
       EmpDao empDao=new EmpDaoImpl();
        System.out.println(Emp.class);
        if(ParameterUtil.isNull(name)||ParameterUtil.isNull(salary)||ParameterUtil.isNull(gender)||ParameterUtil.isNull(edu)||hobbies == null){
            throw new RequestParameterErrorException("请求参数有误");
        }

        Emp emp=new Emp(name,Double.parseDouble(salary),gender,edu,hobbies);
        try {
            empDao.insertEmp(emp);
        } catch (DataAccessException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public void removeEmp(int id) throws ServiceException {
        EmpDaoImpl empDao=new EmpDaoImpl();
        try {
            empDao.deleteEmp(id);
        } catch (DataAccessException e) {
            throw new ServiceException(e.getMessage());
        }
    }

    @Override
    public void modifyEmp() {

    }

    @Override
    public List<Emp> findAll() {
        EmpDaoImpl empDao=new EmpDaoImpl();
        List<Emp> list = null;
        try {
           list= empDao.selectAll();
        } catch (DataAccessException e) {
            e.printStackTrace();
        }
        return list;
    }
}
